<template>
	<view class="passenger-flow">
		<view class="box_9">
			<view class="tab-filter">
				<view class="tabs">
					<view class="tab-item" style="font-size: 26rpx;" :class="{'active': selected_Tab == 1}"
						@click="selectedTab(1)">
						<text>未分班</text>
					</view>
					<view class="tab-item" style="font-size: 26rpx;" :class="{'active': selected_Tab == 2}"
						@click="selectedTab(2)">
						<text>已分班</text>
					</view>
					<view class="tab-item" style="font-size: 26rpx;" :class="{'active': selected_Tab == 3}"
						@click="selectedTab(3)">
						<text>全部学员</text>
					</view>
				</view>
			</view>
			<view class="">
				<scroll-view scroll-y class="listall" v-for="(item,index) in hylist" :key="index"
					@click="handSelect(item)">
					<v-gap style="margin-top: 30rpx;" />
					<view class="d-flex flex-column listsee" :class="{'active1': weekSelect.includes(item.id)}">
						<view class="d-flex flex-row justify-space-between">
							<view class="d-flex flex-row align-center">
								<view class="">
									<image style="width: 80rpx;height: 80rpx;border-radius: 50%;" :src="item.head_img"
										mode=""></image>
								</view>
								<view class="d-flex flex-column" style="margin-left: 20rpx;">
									<view class="" style="font-size: 26rpx;">

										<text>{{item.name || ''}}</text>
										<text style="margin-left: 20rpx;">{{item.sex || ''}}</text>
										<text style="margin-left: 20rpx;">{{item.age || ''}}岁</text>
									</view>
									<view class="" style="color: #c2c2c2;font-size: 24rpx;">
										{{item.mobile || ''}}
									</view>
								</view>
							</view>
							<view class="" style="font-size: 24rpx;">
								编号：{{item.student_id || ''}}
							</view>
						</view>
						<view class="d-flex flex-row" style="font-size: 24rpx;line-height: 50rpx;">
							<view class="" style="width: 50%;">
								<view>{{item.train_id || ''}}-{{item.train_name || ''}}</view>
							</view>
							<view class="">
								<view>{{item.train_item_id || ''}}-{{item.item_name || ''}}</view>
							</view>
						</view>
						<view class="d-flex flex-row" style="font-size: 24rpx;line-height: 50rpx;">
							<view class="" style="width: 50%;">
								<view>{{item.create_at || ''}}</view>
							</view>
							<view class="">
								{{item.hour_num || ''}}
							</view>
							<view class="" style="margin-left: 10rpx;">
								{{item.course_id || ''}}-{{item.course_name || ''}}
							</view>
						</view>
						<view class="d-flex flex-row" style="font-size: 24rpx;line-height: 50rpx;">
							<view class="" style="width: 50%;">
								<view>{{item.custodian || ''}}</view>
							</view>
							<view class="">
								{{item.custodian_mobile || ''}}
							</view>
							<view class="" style="margin-left: 10rpx;">
								{{item.coach_name || ''}}-{{item.area_name || ''}}
							</view>
						</view>
					</view>
				</scroll-view>
				<v-gap height="140rpx" color="#EDF5F5" />
			</view>
			<view class="d-flex flex-row justify-space-between justify-center align-center"
				style="position: fixed;bottom: 0;height: 120rpx;background-color: #fff;width: 100%;padding: 0 8%;z-index: 99;">
				<view class="" @click="selectAllWeeks"
					style="width: 30%;height: 80rpx;background: #57bfff;color: #ffffff;font-size: 24rpx;text-align: center;border-radius: 35rpx;line-height: 80rpx;border:#ec6ff404052b 1rpx solid">
					全选
				</view>
				<view class="" @click="offstudent"
					style="width: 30%;height: 80rpx;background: linear-gradient(0deg, rgba(194, 194, 194, 0.9), rgba(227, 227, 227, 0.9), rgba(230, 230, 230, 0.9));color: #ffffff;font-size: 24rpx;text-align: center;border-radius: 35rpx;line-height: 80rpx;">
					取消
				</view>
				<view class="" @click="addstudent"
					style="width: 30%;height: 80rpx;background: linear-gradient(0deg, rgba(214, 53, 53, 0.9), rgba(255, 64, 64, 0.93), rgba(250, 142, 142, 0.93));color: #ffffff;font-size: 24rpx;text-align: center;border-radius: 35rpx;line-height: 80rpx;">
					提交
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	const personal = require("@/api/personal/index.js");
	const venues = require("@/api/venues/venues.js");
	const train = require("@/api/train/index.js");
	export default {
		data() {
			return {
				filterData: [],
				itemChooselist: {},
				venuelist: [],
				plshow: true,
				weekSelect: [], //选中的
				hylist: [],
				isAllSelect: false, //是否全选
				listQuery: { //分页
					pageNo: 1,
					pageSize: 6,
				},
				totalPage: '', //几页
				studentlist: [],
				searchKey: "",
				selectId3: null,
				weekList3: [],
				selected_Tab: 1,
				classroom: {},
				type: 1
			}
		},
		onLoad(options) {
			console.log(options, options)
			const selectionArrs = JSON.parse(decodeURIComponent(options.selectionArr))
			this.classroom = selectionArrs
			console.log(this.classroom, 'classroom')
			uni.setNavigationBarTitle({
				title: this.classroom.class_name
			});
		},
		onShow() {
			this.listQuery.pageNo = 1
			this.studentindex()
		},
		methods: {
			selectedTab(item) {
				this.listQuery.pageNo = 1
				this.Cardlist = []
				this.selected_Tab = item
				this.type = item
				this.studentindex()
			},
			async studentindex() {
				let that = this;
				let params = {
					course_id: this.classroom.course_id,
					type: this.type
				}
				let res = await train.stu_list(params)
				if (res.code === 1) {
					this.hylist = res.data.data
				}
			},

			ondelete(item, index) {
				let that = this
				uni.showModal({
					title: '提示',
					// 提示文字
					content: '是否删除！',
					// 取消按钮的文字自定义
					cancelText: "取消",
					// 确认按钮的文字自定义
					confirmText: "确定",
					//删除字体的颜色 
					confirmColor: '#000000',
					//取消字体的颜色
					cancelColor: '#999',
					success: function(res) {
						if (res.confirm) {
							let params = {
								id: item.id
							};
							venues.studentdel(params).then(res => {
								if (res.code == 1) {
									uni.$u.toast(res.info);
									setTimeout(() => {
										that.studentindex()
									}, 1000)
								}
							})
						} else {}
					}
				})
			},
			// 新增的全选方法
			selectAllWeeks() {
				if (this.weekSelect.length === this.hylist.length) {
					// 如果已全选，则清空选中数组
					this.weekSelect = [];
				} else {
					// 如果未全选，则选中所有项目
					this.weekSelect = this.hylist.map(item => item.id);
				}
			},
			handSelect(item) {
				let data = item.id;
				// 使用indexOf检查是否已选中，避免重复或遗漏
				const index = this.weekSelect.indexOf(data);
				if (index > -1) {
					// 如果已选中，则移除
					this.weekSelect.splice(index, 1);
				} else {
					// 如果未选中，则添加
					this.weekSelect.push(data);
				}
			},
			handSelects(item) {
				uni.navigateTo({
					url: '../studentdetail/index?student_id=' + item.id
				})
			},
			plbatch() {
				this.plshow = !this.plshow
			},
			confirm(e) {
				uni.navigateTo({
					url: './shaixuan'
				})
				// this.indexArr = e.index;
				// this.valueArr = e.value;

			},
			
			confirm1(data) {
				this.itemChooselist.id = data
			    console.log(data, 'data');
			    // 直接根据接收到的 id 在 venuelist 中查找对应的场馆对象
			    const selectedItem = this.venuelist.find(item => item.id === data);
			    if (selectedItem) {
			        // 将找到的场馆对象赋值给 itemChooselist
			        this.itemChooselist = selectedItem;
			    } else {
			        console.log(`未找到 id 为 ${data} 的场馆对象`);
			    }
				this.studentindex()
			    console.log(this.itemChooselist, 'this.itemChooselist');
			},
			offstudent(){
				uni.navigateBack({
					delta: 1 // 返回上一页面，如果页面栈中只有一个页面则该方法不会生效
				});
			},
			async addstudent() {
				let that = this
				uni.showModal({
					title: '提示',
					// 提示文字
					content: '确认保存？',
					// 取消按钮的文字自定义
					cancelText: "取消",
					// 确认按钮的文字自定义
					confirmText: "确定",
					//删除字体的颜色 
					confirmColor: '#000000',
					//取消字体的颜色
					cancelColor: '#999',
					success: function(res) {
						if (res.confirm) {
							let params = {
								class_id: that.classroom.id,
								ids: that.weekSelect
							};
							train.cls_mangestu(params).then(res => {
								if (res.code == 1) {
									uni.$u.toast(res.info);
									setTimeout(() => {
										that.studentindex()
									}, 1000)
								}
							})
						} else {}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tab-filter {
		background-color: #ffffff;
		padding: 0 32rpx 20rpx 32rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}

	.tabs {
		display: flex;
		border-bottom: 2rpx solid #f0f0f0;
	}

	.tab-item {
		padding: 16rpx 20rpx;
		margin-right: 32rpx;
		position: relative;
	}

	.tab-item.active {
		color: #2979ff;
	}

	.tab-item.active::after {
		content: '';
		position: absolute;
		bottom: -2rpx;
		left: 0;
		right: 0;
		height: 4rpx;
		background-color: #2979ff;
	}

	.passenger-flow {
		width: 100%;
		height: 100vh;
		display: flex;
		flex-direction: column;
		background-color: #EDF5F5;
		padding: 0rpx 0 50rpx 0;
		position: relative;

		.box_9 {
			width: 750rpx;
			height: 100%;
			// margin-bottom: 1rpx;
			display: flex;
			flex-direction: column;

			.tag-list {
				display: flex;
				margin-top: 30rpx;
				padding: 0 20rpx;

				/deep/ view {
					margin-left: 4rpx;
				}
			}

			.box_11 {
				width: 100%;
				height: 130rpx;
				display: flex;
				flex-direction: row;
				background: #ffffff;
				padding: 0 20rpx;

				// .image-wrapper_7 {
				// 	width: 541rpx;
				// 	height: 60rpx;
				// 	flex-direction: row;
				// 	display: flex;
				// 	margin-top: 15rpx;
				// }
				.image-wrapper_7 {
					position: absolute;
					left: 30rpx;
					top: 30rpx;
					width: 541rpx;
					height: 62rpx;
					flex-direction: row;
					display: flex;
				}

				.label_list {
					display: flex;
					flex-direction: column;
					position: absolute;
					justify-content: center;
					/* 相对父元素水平居中 */
					align-items: center;
					/*  子元素相对父元素垂直居中 */
					right: 90rpx;
					width: 80rpx;
					top: 27rpx;

					.label_7 {
						width: 36rpx;
						height: 36rpx;
					}

					.label_77 {
						width: 60rpx;
						height: 36rpx;
						color: #333333;
						font-size: 26rpx;
						text-align: center;
					}
				}

				.label8_list {
					display: flex;
					flex-direction: column;
					position: absolute;
					justify-content: center;
					/* 相对父元素水平居中 */
					align-items: center;
					/*  子元素相对父元素垂直居中 */
					right: 20rpx;
					width: 80rpx;
					top: 27rpx;

					.label_8 {
						width: 36rpx;
						height: 36rpx;
					}

					.label_88 {
						width: 60rpx;
						height: 36rpx;
						color: #333333;
						font-size: 26rpx;
						text-align: center;
					}
				}
			}

			.all_whole {
				width: 100%;
				display: flex;
				flex-direction: column;
				background: #ffffff;

				.all_whole_be {
					display: flex;
					flex-direction: row;
					justify-content: space-around;

					.all_whole_or {
						display: flex;
						flex-direction: column;
						justify-content: center;
						align-items: center;
						width: 20%;
						height: 150rpx;
						border-radius: 20rpx;
					}

					/* 使用类名来设置背景色 */
					.bg-color-all {
						background: linear-gradient(0deg, rgb(173, 201, 246) 0%, rgb(231, 239, 255) 100%);
					}

					.bg-color-reading {
						background: linear-gradient(0deg, #ccffcc 0%, #edffea 100%);
					}

					.bg-color-graduated {
						background: linear-gradient(0deg, #fbdafd 0%, #fdeffd 100%);
					}

					.bg-color-potential {
						background: linear-gradient(0deg, #f9ffcf 0%, #fdffe9 100%);
					}

					.wz-color-all1 {
						font-size: 24rpx;
					}

					.wz-color-all2 {
						color: #3479da;
						font-weight: 600;
						font-size: 26;
					}

					.wz-color-reading2 {
						color: #67ca55;
						font-weight: 600;
						font-size: 26;
					}

					.wz-color-graduated2 {
						color: #a672c6;
						font-weight: 600;
						font-size: 26;
					}

					.wz-color-potential2 {
						color: #b39b64;
						font-weight: 600;
						font-size: 26;
					}
				}

				.all_potent {
					display: flex;
					flex-direction: row;
					justify-content: space-around;
					color: #c2c2c2;
					font-size: 22rpx;
					height: 80rpx;
					width: 100%;
					justify-content: space-between;
					align-items: center;
					padding: 0 20rpx;

					.all_shuju1 {}

					.all_shuju2 {
						display: flex;
						flex-direction: row;
						justify-content: center;
						align-items: center;

						.all_shuju2_img {
							width: 20rpx;
							height: 20rpx;
							margin-right: 10rpx;
						}
					}
				}

				.alls_potent {
					display: flex;
					flex-direction: row;
					justify-content: space-around;
					height: 80rpx;
					width: 100%;
					justify-content: space-between;
					align-items: center;
					padding: 0 20rpx;

					.alls_shuju1 {
						font-size: 28rpx;
					}

					.alls_shuju2 {
						display: flex;
						flex-direction: row;
						justify-content: center;
						align-items: center;

						.alls_shuju2_img {
							width: 20rpx;
							height: 20rpx;
						}
					}
				}
			}

			.listall {
				.listsee {
					background-color: #fff;
					padding: 30rpx;
					border-radius: 10rpx;
					width: 94%;
					margin-left: 3%;
					border: 2rpx #fff solid;
				}

				.active1 {
					border: 2rpx #0000ff solid;
				}
			}

		}
	}
</style>